<template>
	<view>
		<view class="jump-page">
			<image class="wx-img" src="../../static/img/wx_img.png" mode=""></image>
			<view class="tips">
				平台网络服务自动跳转微信授权中...
			</view>
		</view>
	</view>
</template>
<script>
	 import {apiGetUserInfo} from '../../../http/apis.js'
	 import {
	     mapMutations
	 } from 'vuex';
	export default {
		data() {
			return{
				code: '',
				type: '',
				inviteCode: '',
        masterCode:'',
			}
		},
		onLoad(option){
			this.code = option.code
			this.inviteCode = option.inviteCode
      this.masterCode = option.masterCode
			this.loginByWechat()
		},
		methods:{
			...mapMutations(['login']),
			async loginByWechat() {
				if (this.code) {
					uni.request({
						url:this.GLOBAL.BASE_URL+'baseapi/pushBase/getUserInfo',
						method:'get',
					    data:{
						    code: this.code,
                masterCode: this.masterCode,
					    },success:res=>{
              console.log(res)
							if(res.data.code == 1)  {
								uni.removeStorageSync('token')
								this.$msg.showToast(res.data.msg)
								setTimeout(() => {
									uni.navigateTo({//未输入订单号的或者被审核失败
									    url: '/pages/reg/reg?openId=' + res.data.openId + '&inviteCode=' + this.inviteCode
									})
								}, 1000);
							} else if (res.data.code == 2008){
								this.login(res.data.token);
								uni.setStorageSync('token', res.data.token);
								uni.setStorageSync('showNoticeModal', 1);
								uni.switchTab({
								    url: '../home/home'
								});
							} else if(res.data.code == 2021){
                uni.navigateTo({
                  url: '../promotedMaster/discipleList'
                })
              } else if(res.data.code == -1){
								this.$msg.showToast(res.data.msg)
                setTimeout(() => {
                  uni.navigateTo({//未输入订单号的或者被审核失败
                    url: '/pages/reg/reg?openId=' + res.data.openId + '&inviteCode=' + this.inviteCode
                  })
                }, 1000);
								// return
							} else {
                this.login(res.data.token);
								this.$msg.showToast(res.data.msg)
								setTimeout(()=>{
									uni.navigateTo({//正在审核中
										url: '../bindInfo/bindTbAccountxl?type=init'
									})
								},500)
							}
					    }
					})
					// apiGetUserInfo({
					// 	 code: this.code,
					// }).then(res =>{
					//     if(res.data.code == 1)  {
					// 		uni.removeStorageSync('token')
					// 		this.$msg.showToast(res.data.msg)
					// 		setTimeout(() => {
					// 			uni.navigateTo({//未输入订单号的或者被审核失败
					// 			    url: '/pages/reg/reg?openId=' + res.data.openId + '&inviteCode=' + this.inviteCode
					// 			})
					// 		}, 1000);
					// 	} else if (res.data.code == 2008){
					// 		this.login(res.data.token);
					// 		uni.setStorageSync('token', res.data.token);
					// 		uni.setStorageSync('showNoticeModal', 1);
					// 		uni.switchTab({
					// 		    url: '../home/home'
					// 		});
					// 	} else if(res.data.code == -1){
					// 		this.$msg.showToast(res.data.msg)
					// 		return
					// 	} else {
					// 		this.$msg.showToast(res.data.msg)
					// 		this.login(res.data.token);
					// 		setTimeout(()=>{
					// 			uni.navigateTo({//正在审核中
					// 				url: '../bindInfo/bindTbAccount'
					// 			})
					// 		},500)
					// 	}
					// }).catch(res => {
					// 	this.$msg.showToast(res.data.msg)
					// })
				}

			},
			getUrlParam (name) {
				let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				let r = window.location.search.substr(1).match(reg);
				if (r != null) {
					return unescape(r[2]);
				}
				return null;
			},
			isWechat () {
				return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
			}
		}
	}
</script>

<style scoped lang="less">
	.jump-page {
		text-align: center;
		.wx-img {
			width: 90px;
			height: 90px;
			margin-top: 40%;
		}
		.tips {
			font-size: 28upx;
			color: #666666;
			margin-top: 20upx;
		}
	}

</style>
